package org.esprit.ocm.client.ui.ec2;


import com.smartgwt.client.types.VisibilityMode;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.toolbar.ToolStrip;

public class VolumeZone extends SectionStack {

	public VolumeZone() {

		setVisibilityMode(VisibilityMode.MULTIPLE);
		setHeaderHeight(20);

		// creer instanceSection
		SectionStackSection volumeSection = new SectionStackSection(
				"Volumes List");
		volumeSection.setExpanded(true);
		addSection(volumeSection);

		// creer instanceGrid
		final ListGrid volumeGrid = new ListGrid(); 

		// instanceGrid.setShowFilterEditor(true);
		volumeGrid.setFilterOnKeypress(true);
		volumeGrid.setAutoFetchData(true);

		// creer instancetoolstrip
		ToolStrip volumeGridToolStrip = new ToolStrip();
		volumeGridToolStrip.setWidth100();
		volumeGridToolStrip.addFill();

		// ajouter toolstrip a instanceSection
		volumeSection.addItem(volumeGridToolStrip);

		// creer filterButton
		final Button filterButtonOn = new Button("Filter On");
		filterButtonOn.setShowRollOver(true);
		filterButtonOn.setShowDown(true);
		filterButtonOn.setIcon("filter.png");
		filterButtonOn.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {

				volumeGrid.setShowFilterEditor(true);
				volumeGrid.setFilterOnKeypress(true);
			}
		});
		// creer filterButton
		final Button filterButtonOff = new Button("Filter Off");
		filterButtonOff.setShowRollOver(true);
		filterButtonOff.setShowDown(true);
		filterButtonOff.setIcon("filter.png");
		filterButtonOff.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				volumeGrid.setShowFilterEditor(false);
				volumeGrid.setFilterOnKeypress(false);
			}
		});

		final Button runButton = new Button("Create");
		runButton.setShowRollOver(true);
		runButton.setShowDown(true);
		runButton.setIcon("add.png");
		runButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
//				RunInstance runInstance = new RunInstance(null, null, null);
//				runInstance.show();
			}
		});

		final Button refreshButton = new Button("Refresh");
		refreshButton.setShowRollOver(true);
		refreshButton.setShowDown(true);
		refreshButton.setIcon("interact.png");
		refreshButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				SC.say("Refreshed");
			}
		});

		final Button deleteButton = new Button("Delete");
		deleteButton.setShowRollOver(true);
		deleteButton.setShowDown(true);
		deleteButton.setIcon("remove.png");
		deleteButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				SC.say("Removed");
			}
		});

		// ajouter le bouton
		volumeGridToolStrip.addMember(runButton);
		volumeGridToolStrip.addMember(deleteButton);
		volumeGridToolStrip.addMember(refreshButton);
		volumeGridToolStrip.addMember(filterButtonOn);
		volumeGridToolStrip.addMember(filterButtonOff);

		/******************************/
		volumeGrid.setShowRecordComponents(true);
		volumeGrid.setShowRecordComponentsByCell(true);
		volumeGrid.setShowAllRecords(true);
		/******************************/

		// affecter les fields de instanceGrid
		ListGridField volIDField = new ListGridField("volID", "Volume ID");
		ListGridField sizeField = new ListGridField("size",
				"Size");
		ListGridField snapIDField = new ListGridField("snapID", "Snapshot ID");
		ListGridField zoneField = new ListGridField("zone", "Availability zone");
		ListGridField statusField = new ListGridField("status", "Status");
		ListGridField dateField = new ListGridField("date", "Creation date");
		ListGridField instanceField = new ListGridField("instance", "Instance ID");

		volumeGrid.setFields(volIDField, sizeField, snapIDField, zoneField,
				statusField, dateField, instanceField);

		// ajouter instanceGrid a instanceSection
		volumeSection.addItem(volumeGrid);

		// Snap Grid
		final ListGrid snapGrid = new ListGrid(); 
		
		// affecter les fields de snapGrid
		
		ListGridField snapshotIDField = new ListGridField("snapID", "Snapshot ID");
		ListGridField volumeIDField = new ListGridField("volID", "Volume ID");
		ListGridField stateField = new ListGridField("state", "Status");
		ListGridField dateeField = new ListGridField("date", "Creation date");

		snapGrid.setFields(snapshotIDField, volumeIDField, stateField, dateeField);
		
		// snapsection
		SectionStackSection snapSection = new SectionStackSection(
				"Snapshot List");
		snapSection.setExpanded(true);
		addSection(snapSection);
		snapSection.addItem(snapGrid);

		draw();
	}
}
